<?php
class Core_Driver_Secuirtyvariable extends Security {
	
	public function filter_addslashes($variable, $type = 'strip'){
		try {
			if(isset($variable) && (trim($variable) != "")){
				if($type == "add"){
					if(get_magic_quotes_gpc()){
						return $string;
					}
					else {
						if(function_exists('addslashes')){
							$variable = addslashes($variable);
						}
						else {
							$variable = mysql_real_escape_string($variable);
						}
					}
					return $variable;
				}
				else if ($type = 'strip') {
					$variable = stripslashes($variable);
					return $variable;
				}
				else {
					throw new Exception("Coś poszło nie tak. Filtry nie zadziałały jak należy!");
				}
			}
			else {
				throw new Exception("Podana zmienna nie może być pusta!");
			}
		}
		catch(Exception $e){
			return $e->getMessage();
		}
	}
	
	public function filter_strip_tags($variable){
		try {
			if(isset($variable) && (trim($variable) != "")){
				$variable = strip_tags($variable);
				return $variable;
			}
			else {
				throw new Exception("Podana zmienna nie może być pusta!");
			}
		}
		catch(Exception $e){
			return $e->getMessage();
		}
	}
	
	public function filter_entities($variable){
		try {
			if(isset($variable) && (trim($variable) != "")){
				$variable = htmlentities($variable);
				return $variable;
			}
			else {
				throw new Exception("Podana zmienna nie może być pusta!");
			}
		}
		catch(Exception $e){
			return $e->getMessage();
		}
	}
	
	public function filter_htmlspecialchar($variable){
		try {
			if(isset($variable) && (trim($variable) != "")){
				$variable = htmlspecialchars($variable);
				return $variable;
			}
			else {
				throw new Exception("Podana zmienna nie może być pusta!");
			}
		}
		catch(Exception $e){
			return $e->getMessage();
		}
	}
}